<?php
//echo 'ok ok ok';
defined('_JEXEC') or die('Restricted access');

$datetimenow = date("YmdHi");

//if (isset($_POST['fromdate'])) $fromdate = $_POST['fromdate'];	else $fromdate = booking_helper::DateHuman($datetimenow);
if (isset($_POST['fromdate']))
    $fromdate = $_POST['fromdate']; else
    $fromdate = "";
if (isset($_POST['fromtime']))
    $fromtime = $_POST['fromtime']; else
    $fromtime = '00:00';
//if (isset($_POST['todate'])) $todate = $_POST['todate'];	else $todate = '31/12/'.date('Y');		//24/10/2008
if (isset($_POST['todate']))
    $todate = $_POST['todate']; else
    $todate = "";  //24/10/2008
if (isset($_POST['totime']))
    $totime = $_POST['totime']; else
    $totime = '23:59';

$fromdate = booking_helper::repair_format($fromdate);
$fromtime = booking_helper::repair_format($fromtime);
$todate = booking_helper::repair_format($todate);
$totime = booking_helper::repair_format($totime);
?>

<div class="booking">
    <form action="index.php" method="post" name="adminForm">

        <table class="adminform">
            <tr>
                <td width="100%">
<?php echo JText::_(SEARCH); ?>
                    From (d/m/y):
<?php echo JHTML::_('calendar', $fromdate, "fromdate", "fromdate", '%d/%m/%Y'); ?>
                    <input name="fromtime" class="text_area"  size="5" maxlength='5' value="<?php echo $fromtime; ?>" />&nbsp;&nbsp;
                    To (d/m/y):
<?php echo JHTML::_('calendar', $todate, "todate", "todate", '%d/%m/%Y'); ?>
                    <input name="totime" class="text_area"  size="5" value="<?php echo $totime; ?>" maxlength='5' />
                    <button onclick="this.form.submit();"><?php echo JText::_(GO); ?></button>
                    <button onclick="this.form.getElementById('fromdate').value='';this.form.getElementById('todate').value='';this.form.submit();"><?php echo JText::_('Reset'); ?></button>
                </td>
                <td nowrap="nowrap">
<?php echo $this->lists['payment']; ?>
<?php echo $this->lists['state']; ?>
                </td>
            </tr>
        </table>

        <table class="adminlist" cellspacing="1">
            <thead>
                <tr>
                    <th width="5"><?php echo JText::_(NUM); ?></th>
                    <th width="20%"><?php echo JText::_(NAME); ?></th>
                    <th width="10%"><?php echo JText::_(PICK_UP); ?></th>
                    <th width="10%"><?php echo JText::_(RETURN_DATE); ?></th>
                    <th width="5%"><?php echo JText::_(DRIVERID); ?></th>
                    <th width="20%"><?php echo JText::_(FROM); ?></th>
                    <th width="20%"><?php echo JText::_(TO); ?></th>
                    <th width="5%"><?php echo JText::_(STATE); ?></th>
                    <th width="10%"><?php echo JText::_(PRICE); ?></th>
                    <th width="10%"><?php echo JText::_(PAYMENT); ?></th>
                    <th width="10%"><?php echo JText::_(ID); ?></th>
                    <th width="10%"><?php echo JText::_(INVOICE); ?></th>
                </tr>
            </thead>

            <tfoot>
                <tr>
                    <td colspan="11">
                <?php echo $this->pageNav->getListFooter(); ?>
                            </td>
                        </tr>
                    </tfoot>

                    <tbody>
                <?php
                        $k = 0;
                        for ($i = 0, $n = count($this->rows); $i < $n; $i++)
                        {
                            $row = $this->rows[$i];

                            $link = 'index.php?option=com_taxibooking&amp;controller=orders&amp;task=edit&amp;cid[]=' . $row->id;

                            if ($row->state == 1)
                            {
                                $img = 'tick.png';
                                $inv_img = 'j_button2_readmore.png';
                                $alt = JText::_(ACCEPTED);
                                $inv_alt = JText::_(INVOICE);
                                $state = 1;
                            }
                            else if ($row->state == 0)
                            {
                                $img = 'publish_x.png';
                                $alt = JText::_(REJECTED);
                                $state = 0;
                            }
                            else if ($row->state == -1)
                            {
                                $img = 'disabled.png';
                                $alt = JText::_(ARCHIVED);
                                $state = -1;
                            }
                            else if ($row->state == -2)
                            {
                                $img = 'publish_r.png';
                                $alt = JText::_(WAITING);
                                $state = -2;
                            }
                ?>
                    <tr class="<?php echo "row$k"; ?>">
                        <td><?php echo $this->pageNav->getRowOffset($i); ?></td>
                        <td align="center"><a href="<?php echo $link; ?>"><?php echo $row->names; ?></a></td>
                        <td align="center"><?php echo booking_helper::DateTimeHuman($row->datetime1); ?></td>
                        <td align="center"><?php echo booking_helper::DateTimeHuman($row->datetime2); ?></td>
                        <td align="center"><?php echo $row->driver_id; ?></td>
                                <td align="center"><?php echo $row->begin; ?></td>
                                <td align="center"><?php echo $row->end; ?></td>
                                <td align="center"><img src="templates/bluestork/images/admin/<?php echo $img; ?>" width="16" height="16" border="0" title="<?php echo $alt; ?>" alt="<?php echo $alt; ?>" /></td>

                                <td align="center"><?php echo number_format($row->cprice, 2, '.', ','); ?></td>
                                <td align="center"><?php echo $row->payment; ?></td>
                                <td align="center"><?php echo $row->id; ?></td>
                                <td align="center">
<?php
$pdf_invoice = "components/com_taxibooking/documents/{$row->id}.pdf";
if ($row->state == 1 && file_exists($pdf_invoice)):

        ?>
                                        <a href="<?php echo $pdf_invoice ?>">
                                            <img src="templates/bluestork/images/admin/<?php echo $inv_img; ?>" width="16" height="16" border="0" title="<?php echo $inv_alt; ?>" alt="<?php echo $inv_alt; ?>" />
                                        </a>                
<?php endif; ?>
                                            </td>
                                        </tr>
<?php $k = 1 - $k;
                            } ?>
                                </tbody>

                            </table>

                            <input type="hidden" name="boxchecked" value="0" />
                            <input type="hidden" name="option" value="com_taxibooking" />
                            <input type="hidden" name="controller" value="orders" />
                            <input type="hidden" name="view" value="orders" />
                            <input type="hidden" name="task" value="" />
                            <input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
                            <input type="hidden" name="filter_order_Dir" value="" />
<?php echo JHTML::_('form.token'); ?>
    </form>
</div>